import { FORM_ITEM_1, FORM_ITEM_2 } from '@const';
import { type CheckboxOption } from '@components/showHideFormItem.vue';

export const getFormItemControls = () => {
  const formItemControl = JSON.parse(localStorage.getItem('formItemControl') || '{}');

  return {
    list1: formItemControl?.list1 ?? FORM_ITEM_1,
    list2: formItemControl?.list2 ?? FORM_ITEM_2
  }
}

export const showHideFormItemsByData = () => {
  const {list1, list2} = getFormItemControls();

  [...list1, ...list2].forEach((item: CheckboxOption) => {
    if(!item.show) {
      const elem = document.querySelector(item.value) as HTMLElement;
      elem.style.display = 'none';
    }
  })
}
